package com.example.fraud;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class FraudReviewService {

    private final FraudCheckHistoryRepository fraudCheckHistoryRepository;

    public FraudReviewService(FraudCheckHistoryRepository fraudCheckHistoryRepository) {
        this.fraudCheckHistoryRepository = fraudCheckHistoryRepository;
    }

    public Boolean isFraudulentCustomer(String customerEmail) {
        log.info("Fraud check customer with Email: {}", customerEmail);

        // 根据文档，test2@example.com 有不诚信行为，应该拒绝注册
        // 这里实现具体的征信检查逻辑
        if ("test2@example.com".equals(customerEmail)) {
            log.info("检测到不诚信用户: {}", customerEmail);

            // 可以保存到征信检查历史记录
            FraudCheckHistory fraudCheckHistory = FraudCheckHistory.builder()
                    .email(customerEmail)
                    .isFraudster(true)
                    .build();
            fraudCheckHistoryRepository.save(fraudCheckHistory);

            return true;  // 有征信问题
        }

        // 其他用户正常通过
        FraudCheckHistory fraudCheckHistory = FraudCheckHistory.builder()
                .email(customerEmail)
                .isFraudster(false)
                .build();
        fraudCheckHistoryRepository.save(fraudCheckHistory);

        log.info("用户征信检查通过: {}", customerEmail);
        return false;  // 无征信问题
    }
}
